//
//  WJKeyChainUtils.m
//  JerryIos
//
//  Created by 王军 on 2018/2/11.
//  Copyright © 2018年 王军. All rights reserved.
//

#import "WJKeyChainUtils.h"

@interface WJKeyChainUtils()

@end

@implementation WJKeyChainUtils

static WJKeyChainUtils *instance;

+(instancetype) getInstance{
    @synchronized(self){
        if (!instance) {
            instance = [[self alloc] init];
        }
    }
    return instance;
}

static UICKeyChainStore *keychain;
//初始化
+(void)initialize {
    //方式一
//    keychain = [UICKeyChainStore keyChainStoreWithService:@"com.jerry.JerryIos"];
    //方式二
    keychain = [UICKeyChainStore keyChainStoreWithService:@"com.jerry.JerryIos"
                                                   accessGroup:@"jerryios.share"];
}

//增加
-(void) save:(NSString *)key value:(NSString *)value {
    //方式一
//    keychain[key] = value;
    //方式二
//    [keychain setString:value forKey:key];
    //方式三
    if (![keychain setString:value forKey:key]) {
        NSLog(@"error  error");
    }
}

//获取
-(NSString *)query:(NSString *)key {
   
    //方式一
    NSString *value = keychain[key];
    //方式二
//    NSData *data = [keychain dataForKey:key];
    
    return value;
}

//移除
-(void) remove:(NSString *)key {
    //方式一
//    self.keychain[key] = nil;
    //方式二
    [keychain removeItemForKey:key];
}

@end
